﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using LM.Negocio.Objetos;

namespace LM.Repositorios.Maps
{
    public class DependenteMap : EntityTypeConfiguration<Dependente>
    {
        public DependenteMap()
        {
            this.HasKey(t => t.Codigo);

            this.Property(t => t.Nome)
                .IsRequired()
                .HasMaxLength(250);

            this.Property(t => t.Cpf)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Cnh)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Dependente");
            this.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("Id"); 
            this.Property(t => t.Codigo).HasColumnName("Codigo");
            this.Property(t => t.ClienteId).HasColumnName("ClienteId");
            this.Property(t => t.Nome).HasColumnName("Nome");
            this.Property(t => t.Cpf).HasColumnName("Cpf");
            this.Property(t => t.Cnh).HasColumnName("Cnh");

            // Relationships
            this.HasRequired(t => t.Cliente)
                .WithMany(t => t.Dependentes)
                .HasForeignKey(d => d.ClienteId);
		}
    }
}
